package demo;

import java.util.Arrays;

/**
 * @description:
 * @author: GX
 * @time: 2025/10/28 9:34
 */
public class leetcode27 {
    public int removeElement(int[] nums, int val) {
        int j = 0;
        for(int i = 0;i < nums.length; i++){
            if(nums[i] != val){
                nums[j] = nums[i];
                j++;
            }
        }
        return j;
    }
    public static void main(String[] args){
        int[] nums = {0,1,2,2,3,0,4,2};
        int val = 2;
        int j = new leetcode27().removeElement(nums,val);
        System.out.println(j);
        System.out.println(Arrays.toString(nums));
    }
}
